package com.xiaolin.dao.impl;

import com.xiaolin.bean.Shopp;
import com.xiaolin.dao.BaseDAO;
import com.xiaolin.dao.ShoppDAO;

import java.sql.Connection;
import java.util.List;

public class AllShoppDAOImol extends BaseDAO<Shopp> implements ShoppDAO {

    @Override
    public void insert(Connection conn, Shopp sp) {
        String sql = "INSERT INTO allshopp(name,price,profile,quantity,img,type) VALUES(?,?,?,?,?,?)";
        update(conn, sql,sp.getName(),sp.getPrice(),sp.getProfile(),sp.getQuantity(),sp.getImg(),sp.getType());
    }

    @Override
    public void updateById(Connection conn, Shopp sp) {
        String sql = "UPDATE allshopp SET quantity = ? WHERE id = ?";
        update(conn, sql,sp.getQuantity(),sp.getId());
    }

    /**
     * @param conn
     * @param id
     * @return
     */
    @Override
    public Shopp getShopp(Connection conn, String id) {
        String sql = "SELECT * FROM allshopp WHERE id = ?";
        Shopp instance = getInstance(conn, sql, id);
        return instance;
    }

    @Override
    public List<Shopp> getAll(Connection conn) {
        String sql = "SELECT * FROM allshopp";
        List<Shopp> list = getForList(conn, sql);
        return list;
    }
}
